package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.SingleShopDetailsActivity;
import com.zzk.lanouhn.myapplication1.modles.SingleGoodDetails;

/**
 * Created by lanouhn on 16/9/13.
 */
public class SingleGoodWellAdapter extends RecyclerView.Adapter<SingleGoodWellAdapter.wellViewHolder>{

    private Context context;
    private SingleGoodDetails singleGoodDetails;

    public SingleGoodWellAdapter(Context context, SingleGoodDetails singleGoodDetails) {
        this.context = context;
        this.singleGoodDetails = singleGoodDetails;
    }

    @Override
    public wellViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_wellgoods_singlegood,null);
        wellViewHolder holder=new wellViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(wellViewHolder holder, int position) {
        final SingleGoodDetails.DataBean.ProductListBean bean=singleGoodDetails.getData().getProduct_list().get(position);
        Picasso.with(context).load(bean.getPic()).into(holder.iv_pic);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, SingleShopDetailsActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString("singleId",bean.getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return singleGoodDetails.getData().getProduct_list().size();
    }

    public class wellViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv_pic;
        public wellViewHolder(View itemView) {
            super(itemView);
            iv_pic= (ImageView) itemView.findViewById(R.id.iv_goodPic_well_singlegood);
        }
    }
}
